package org.hive.testserver.gwt.ui.page;

import java.util.Arrays;

import org.hive.testserver.gwt.model.TreeFolder;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treegrid.TreeGrid;
import com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer;
import com.google.gwt.user.client.Element;

public class OverViewPage extends LayoutContainer {

	@Override
	protected void onRender(Element parent, int index) {
		ContentPanel cp = new ContentPanel();
		cp.setBodyBorder(false);
		cp.setHeaderVisible(false);
		cp.setButtonAlign(HorizontalAlignment.CENTER);
		cp.setLayout(new FitLayout());
		cp.setFrame(true);
		cp.setSize(600, 300);

		TreeStore<ModelData> store = new TreeStore<ModelData>();

		TreeFolder model = createDummyData();
		
		store.add(model.getChildren(), true);

	    ColumnConfig name = new ColumnConfig("project", "Project", 100);
	    name.setRenderer(new TreeGridCellRenderer<ModelData>());
	    ColumnConfig date = new ColumnConfig("runs", "Runs", 100);
	    
	    ColumnModel columModel = new ColumnModel(Arrays.asList(name, date));
	    
		
		TreeGrid<ModelData> tree = new TreeGrid<ModelData>(store, columModel);
		tree.setBorders(true);
//		tree.getStyle().setLeafIcon(Resources.ICONS.music());
		tree.setAutoExpandColumn("name");
		tree.setTrackMouseOver(false);

		cp.add(tree);

		add(cp);
	}
	

	private TreeFolder createDummyData() {
		TreeFolder[] folders = new TreeFolder[1];
		TreeFolder treeFolder = new TreeFolder("HWNG");
		folders[0] = treeFolder;
		
		TreeFolder root = new TreeFolder("root");
		root.add(treeFolder);
		return root;
	}
}
